<html>
<head>
<link rel="stylesheet" type="text/css" href="/include/layout.css" />
<script type='text/javascript' src='/analytics/googleAnalytics.js'></script>

<!-- open x ads -->
<script type='text/javascript' src='http://quantotech.com/openx-2.8.8/www/delivery/spcjs.php?id=1&amp;target=_blank'></script>

<body>

<?php	
	require ("./include/defines.php");
	require ("./include/mysqli_connect.php");
	require ("./include/source_factory.php");
	require ("./Drivers/sourceAdapter.php");

	$id = mysqli_real_escape_string ($dbc, $_GET['id']);
	if ($id == null) {
		print "Error: id must be defined in the url";
	}
	// Randomly generate a number to decide the ad source
	$type = switchAdSource( rand(0,100) );
	
	// Generate Ad source with Factory Method
	$source = SourceFactory::makeSource($type);
	
	// Make sure we are using a valid adapter
	if (!($source instanceof SourceAdapter)) {
		print 'Error: class MUST extend SourceAdapter';
	}
	
	$source->retrieveProfile($dbc, $id);
	$source->matchProfile();
	$source->getHTML();
	$source->updateProfile();






function switchAdSource($randomNum)
{
	if ($randomNum < HOUSE_AD_PERCENTAGE){
		// Display House Ads
		return "House_Ad";
	}else if ( $randomNum < AMAZON_AFFLIATE_PERCENTAGE ) {
		// Display AMAZON AFFLIATE ADS
		return "Amazon_Affliate";
	}else if ( $randomNum < NEWS_FEED_PERCENTAGE ) {
		// Display NEWS FEED
		return "News_Feed";
	}else if ( $randomNum < BUY_SELL_ADS_PERCENTAGE) {
		// Display BUY_SELL_ADS
		return "Buy_Sell_Ads";
	}else if ( $randomNum < DIRECT_ADS_PERCENTAGE){
		// DISPLAY DIRECT ADS
		return "Direct_Ads";
	}else {
		// DISPLAY ERROR!
		echo 'Cannot Display Ad';
	}
	
	
}	
	
	
	
?>

</body>
